package gitee.derumin.lib_for_derumin.commands.suggestionproviders;

import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import gitee.derumin.lib_for_derumin.helpers.config.ConfigHelper;
import net.minecraft.server.command.ServerCommandSource;

import java.util.concurrent.CompletableFuture;

public class ConfigNameSuggestionProvider implements SuggestionProvider<ServerCommandSource> {
    public static final ConfigNameSuggestionProvider PROVIDER = new ConfigNameSuggestionProvider();
    @Override
    public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {
        String name;
        try {
            name = StringArgumentType.getString(context, "playername");
        }catch (Exception e){
            name = null;
        }
        if (name == null){
            for (String name1 : ConfigHelper.getConfigNames()){
                builder.suggest(name1);
            }
        }
        return builder.buildFuture();
    }
}
